package proxy.general;

import java.lang.reflect.*;

/**
 * @Author：LJ
 * @Description：
 * @Date: 2017/11/27
 * @Modified By:
 */
public class SubjectDynamicProxy {

    public static <T> T newProxyInstance(Subject subject) {
        Class cls = subject.getClass();
        ClassLoader classLoader = cls.getClassLoader();
        Class<?>[] classes = cls.getInterfaces();
        InvocationHandler invocationHandler = new ProxyInvocationHandler(subject);
        return (T) java.lang.reflect.Proxy.newProxyInstance(classLoader, classes, invocationHandler);
    }
}
